/*
 * Utility.java
 *
 * Created on April 26, 2006, 4:04 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package com.genITeam.ria.utility;

import java.math.BigDecimal;
import java.sql.Time;
import java.text.*;
import java.util.*;


public class Utility {
	public static final long MILLISECOND_IN_DAY    = 24 * 60 * 60 * 1000;
	public static final long MILLISECOND_IN_HOUR   = 60 * 60 * 1000;
	public static final long MILLISECOND_IN_MINUTE = 60 * 1000;
	public static final long MILLISECOND_IN_SECOND = 1000;
	public static final int  SECONDS_IN_YEAR = 60*60*24*365;

//	private static Date hostDownStartTime   = null;
//	private static Date hostDownEndTime     = null;
//	private static Date previousTime        = null;
	public static final long MILLISECONDS_IN_A_DAY = 1000*60*60*24;
/**
 * Utility constructor comment.
 */
private Utility() {
	super();
}
/**
 * Insert the method's description here.
 * Creation date: (1/19/01 9:00:30 PM)
 * @return int
 * @param firstDate java.util.Date
 * @param secondDate java.util.Date
 */
public static int compareDates(java.util.Date firstDate, java.util.Date secondDate) {
	int returnValue = 0;

	if(firstDate.after(secondDate)){
		returnValue = 1;
	} else {
		if(firstDate.before(secondDate)){
			returnValue = -1;
		}
	}

	return returnValue;
}


public static String cleanString(String str){    
    return  str.replaceAll("'",""); 
}


public static boolean isOnTime(java.util.Date dueDate, java.util.Date doneDate) {
	

	if(dueDate == null){
		return true;
	}else if(doneDate == null){
		doneDate = new Date(System.currentTimeMillis());		
	}

	return dueDate.after(doneDate);
}

/**
 * Insert the method's description here.
 * Creation date: (4/24/2004 12:37:57 PM)
 * @return java.lang.String
 * @param amount double
 * @param outputAmountFormat java.lang.String
 */
public static String convertAmountDoubleToString(double amount, String outputAmountFormat) {
	return new DecimalFormat(outputAmountFormat).format(amount);
}
/**
 * Insert the method's description here.
 * Creation date: (4/24/2004 12:42:13 PM)
 * @return double
 * @param amount java.lang.String
 * @param inputAmountFormat java.lang.String
 */
public static double convertAmountStringToDouble(String amount, String inputAmountFormat) throws Exception {
	try {
	return new DecimalFormat(inputAmountFormat).parse(amount).doubleValue();
	} catch (ParseException pEx) {
		throw new Exception(pEx.getMessage());
	}
}
/**
 * Insert the method's description here.
 * Creation date: (4/24/2004 11:45:23 AM)
 * @return java.lang.String
 * @param newDate java.util.Date
 * @param outputDateFormat java.lang.String
 */
public static String convertDateToString(Date newDate, String outputDateFormat)  {

	if(newDate == null){
		return "" ;
	}

	return new SimpleDateFormat(outputDateFormat).format(newDate);
}
/**
 * Insert the method's description here.
 * Creation date: (4/24/2004 12:37:57 PM)
 * @return java.lang.String
 * @param amount int
 * @param outputAmountFormat java.lang.String
 */
public static String convertNumberIntToString(int amount, String outputAmountFormat) {
	return new DecimalFormat(outputAmountFormat).format(amount);
}
/**
 * Insert the method's description here.
 * Creation date: (4/24/2004 11:45:23 AM)
 * @return java.sql.Date
 * @param newDate java.util.Date
 * @param outputDateFormat java.lang.String
 */
public static java.sql.Date convertStringToDate(String newDate, String inputDateFormat)  {	
	java.sql.Date returnValue = null;
	
	
	if(newDate==null || newDate.equals("") ){
		return null;
	}
	
	try
	{
		returnValue = new java.sql.Date(new SimpleDateFormat(inputDateFormat).parse(newDate).getTime());
	}
	catch (Exception e){}
	return returnValue;
}

public static Time convertStringToTime(String newDate, String inputDateFormat)  {	
	Time returnValue = null;
	
	
	if(newDate==null || newDate.equals("") ){
		return null;
	}
	
	try
	{
		returnValue = new Time(new SimpleDateFormat(inputDateFormat).parse(newDate).getTime());
	}
	catch (Exception e){}
	return returnValue;
}

/**
 * Insert the method's description here.
 * Creation date: (4/24/2004 11:45:23 AM)
 * @return java.sql.Date
 * @param newDate java.util.Date
 * @param outputDateFormat java.lang.String
 * this method is for workflow required format
 * new format will be dd-mmm-yyyy
 */
public static String convertDateFormat(java.sql.Date newDate)  {	
	String returnValue = null;
	
	final SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
	 
	if(newDate==null || newDate.equals("") ){
		return "";
	}
	
	try
	{
		//String newDateString = newDate.toString();//changeFormate(newDate);
		returnValue = formatter.format(newDate);
	}
	catch (Exception e){}
	return returnValue;
}

/**
 * Insert the method's description here.
 * Creation date: (4/24/2004 11:45:23 AM)
 * @return java.sql.Date
 */
public static java.sql.Date getLowDate()  {
	java.sql.Date returnValue = null;
	try
	{
		returnValue = new java.sql.Date(new SimpleDateFormat(
						FormatConstants.MMDDCCYY_SEPARATOR_SLASH).
							parse("1/1/1899").getTime());
	}
	catch (Exception e){}
	return returnValue;
}

/**
 * Insert the method's description here.
 * Creation date: (5/20/02 10:05:18 AM)
 * @return java.lang.String
 */
public static String eliminateDecimalPoint(String value) {
	int length = 0;
	int decimalPosition = 0;
	String returnValue = null;

	if (value != null) {
		length = value.length();
		decimalPosition = value.lastIndexOf(".");

		if (decimalPosition > 0) {
			returnValue  = value.substring(0, decimalPosition);
			returnValue += value.substring(decimalPosition + 1, length);
		} else {
			if (decimalPosition == 0) {
				returnValue = value.substring(decimalPosition + 1, length);
			} else {
				returnValue = value;
			}
		}
	}

	return returnValue;
}

/**
 * This method return current date of system after converting it into the MDY format
 *
 * @return  d 	String 		return converted date
 */
public static String getCurrentDate() {

    Date d = new Date(System.currentTimeMillis());
	return convertDateToString(d,FormatConstants.MMDDCCYY_SEPARATOR_SLASH);
}
/**
 * Insert the method's description here.
 * Creation date: (1/19/01 9:00:30 PM)
 * @return long
 * @param firstDate java.util.Date
 * @param secondDate java.util.Date
 * firstDate must be less than secondDate.
 * This method will return difference of two dates firstDate and secondDate in millisecond.
 * if firstDate is greater than secondDate then this method will return -1.
 */
public static long getDatesDifference(java.util.Date firstDate, java.util.Date secondDate) {
	long returnValue = 0;
	java.util.Calendar calendar = java.util.Calendar.getInstance();

	calendar.setTime(firstDate);
	long dayOfYear1      = calendar.get(Calendar.DAY_OF_YEAR);
	long hourOfDay1      = calendar.get(Calendar.HOUR_OF_DAY);
	long minuteOfHour1   = calendar.get(Calendar.MINUTE);
	long secondOfMinute1 = calendar.get(Calendar.SECOND);
	long milliSecond1    = calendar.get(Calendar.MILLISECOND);

	calendar.setTime(secondDate);
	long dayOfYear2      = calendar.get(Calendar.DAY_OF_YEAR);
	long hourOfDay2      = calendar.get(Calendar.HOUR_OF_DAY);
	long minuteOfHour2   = calendar.get(Calendar.MINUTE);
	long secondOfMinute2 = calendar.get(Calendar.SECOND);
	long milliSecond2    = calendar.get(Calendar.MILLISECOND);

	if(compareDates(firstDate,secondDate) <= 0){
		long firstMilliSeconds  = 0;
		long secondMilliSeconds = 0;

		firstMilliSeconds += dayOfYear1 * MILLISECOND_IN_DAY;
		firstMilliSeconds += hourOfDay1 * MILLISECOND_IN_HOUR;
		firstMilliSeconds += minuteOfHour1 * MILLISECOND_IN_MINUTE;
		firstMilliSeconds += secondOfMinute1 * MILLISECOND_IN_SECOND;
		firstMilliSeconds += milliSecond1;

		secondMilliSeconds += dayOfYear2 * MILLISECOND_IN_DAY;
		secondMilliSeconds += hourOfDay2 * MILLISECOND_IN_HOUR;
		secondMilliSeconds += minuteOfHour2 * MILLISECOND_IN_MINUTE;
		secondMilliSeconds += secondOfMinute2 * MILLISECOND_IN_SECOND;
		secondMilliSeconds += milliSecond2;

		returnValue = secondMilliSeconds - firstMilliSeconds -1;


	} else {
		returnValue = -1;
	}

	return returnValue;
}

/**
 * This method calculate difference in from date and to date
 * @param	fromDate 	Date		To Date
 * @param	toDate 		Date		To Date
 * @return  days 		Long  		return total difference
 */
public static long getDifferenceInDays(Date fromDate, Date toDate) {

	//if any of the argument is current date
	//then please pass Util.getCurrentSQLDate()
	//don't pass new java.sql.Date(System.currentTimeMillis())

    long diff = (toDate.getTime()) - (fromDate.getTime());

    diff 	  = diff / MILLISECONDS_IN_A_DAY;
    if(diff < 0)diff=-1*diff;
	
    return (diff);
}
/**
 * Insert the method's description here.
 * Creation date: (6/28/2002 7:12:24 PM)
 * @return java.lang.String
 * @param fillerValue java.lang.String
 * @param numberOfOccurences int
 */
public static String getFiller(String fillerValue, int numberOfOccurences) {
	return replicateString(fillerValue, numberOfOccurences);
}
/**
 * Insert the method's description here.
 * Creation date: (2/08/01 12:20:40 AM)
 * @return int
 * This metod returns ScheduledHostDownTime in Minutes.
 */
public static int getScheduledHostDownTime() {
	int returnValue = 0;

/* Start of CR# MCA/CRF/PI/052 */
/* According to this CRF new strategy is adopted to find MCA server Availability
   through data area flag instead of host down start and end times */
/*	Calendar calendar    = Calendar.getInstance();
	Date currentTime     = calendar.getTime();

	updateHostDownTime(currentTime);

	long minutes = getDatesDifference(currentTime,hostDownEndTime) / MILLISECOND_IN_MINUTE;

	returnValue = new Long(minutes).intValue(); */
/* End  of CR# MCA/CRF/PI/052 */

	return returnValue;
}
/**
 * Insert the method's description here.
 * Creation date: (3/16/01 8:08:45 PM)
 * @return java.lang.String
 * @param numberOfSpaces int
 */
public static String getSpaces(int numberOfSpaces) {
	return replicateString(" ", numberOfSpaces);
}
/**
 * Insert the method's description here.
 * Creation date: (3/16/01 8:08:45 PM)
 * @return java.lang.String
 * @param numberOfZeroes int
 */
public static String getZeroes(int numberOfZeroes) {
	return replicateString("0", numberOfZeroes);
}
/**
 * Insert the method's description here.
 * Creation date: (7/16/2002 4:52:18 PM)
 * @return java.lang.String
 * @param dateValue java.lang.String
 */
public static boolean isCurrentDate(String dateMMDDYY_SEPARATOR_SLASH) {
	boolean returnValue = false;
    try {
	   	SimpleDateFormat sdf = new SimpleDateFormat(FormatConstants.MMDDYY_SEPARATOR_SLASH);
	   	Date currentDate = new Date(sdf.parse(sdf.format(new Date(System.currentTimeMillis()))).getTime());
	    Date compareDate = new Date(sdf.parse(dateMMDDYY_SEPARATOR_SLASH).getTime());
	    returnValue = currentDate.compareTo(compareDate) == 0;
    } catch (Exception exception) {
	    exception.getMessage();
    }
    return returnValue;
}

/**
 * This method returns the current SQL Date.
 * @return  invalid session
 */

public static java.sql.Date getCurrentSQLDate()
{
	return new java.sql.Date(new java.util.Date().getTime());
}
/**
 * Insert the method's description here.
 * Creation date: (7/16/2002 4:52:18 PM)
 * @return java.lang.String
 * @param dateValue java.lang.String
 */

public static boolean isPassedDate(String dateMMDDYY_SEPARATOR_SLASH) {
	boolean returnValue = false;
    try {
	   	SimpleDateFormat sdf = new SimpleDateFormat(FormatConstants.MMDDYY_SEPARATOR_SLASH);
	   	Date currentDate = new Date(sdf.parse(sdf.format(new Date(System.currentTimeMillis()))).getTime());
	    Date compareDate = new Date(sdf.parse(dateMMDDYY_SEPARATOR_SLASH).getTime());
	    returnValue = currentDate.after(compareDate);
    } catch (Exception exception) {
	    exception.getMessage();
    }
    return returnValue;
}

/**
 * Insert the method's description here.
 * Creation date: (2/08/01 12:20:40 AM)
 * @return boolean
 */
public static boolean isScheduledHostDownTime() {
	boolean returnValue = false;

/* Start of CR# MCA/CRF/PI/052 */
/* According to this CRF new strategy is adopted to find MCA server Availability
   through data area flag instead of host down start and end times */

/*  Calendar calendar   = Calendar.getInstance();
	Date currentTime    = calendar.getTime();

	updateHostDownTime(currentTime);

	if(Utility.compareDates(currentTime,hostDownStartTime) >= 0 &&
		Utility.compareDates(currentTime,hostDownEndTime) <= 0){
			returnValue = true;
	}

	com.wellsfargo.ibps.controller.LogController.createProfile("In isScheduledHostDownTime()");
	com.wellsfargo.ibps.controller.LogController.createProfile("Current Time = "+currentTime.toString().trim());
	com.wellsfargo.ibps.controller.LogController.createProfile("Start   Time = "+hostDownStartTime.toString().trim());
	com.wellsfargo.ibps.controller.LogController.createProfile("End     Time = "+hostDownEndTime.toString().trim());
	com.wellsfargo.ibps.controller.LogController.createProfile("Return Value = "+returnValue);
*/
/* End   of CR# MCA/CRF/PI/052 */
	return returnValue;
}
/**
 * Insert the method's description here.
 * Creation date: (2/08/01 12:20:40 AM)
 * @return boolean
 * @param startTime long
 * @param timeOutValue long
 */
public static boolean isTimeOut(long startTime, long timeOutValue) {
	boolean returnValue = false;

	long currentTime = System.currentTimeMillis();
	long elapsedTime = currentTime - startTime;

	if(elapsedTime > timeOutValue) {

		returnValue = true;
	}

	return returnValue;
}
/**
 * Insert the method's description here.
 * Creation date: (7/19/2002 5:05:30 PM)
 * @return java.lang.String
 * @param sourceString java.lang.String
 * @param separatorString java.lang.String
 */
public static String replaceSeparatorFromData(String sourceString, String separatorString, int replaceChar) throws Exception{
	int lastpos = 0;
	int fromIndex = 0;
	StringBuffer sb = new StringBuffer("");


	if (sourceString != null) {
		fromIndex = sourceString.indexOf(separatorString,0);
		sb.append(sourceString.indexOf(separatorString,0) >= 0 ? "" : sourceString);
		while (fromIndex >= 0) {
			sb.append(sourceString.substring(lastpos, fromIndex));
			if (sourceString.substring(fromIndex, fromIndex + 3).trim().equals(separatorString) ) {
				sb.append((char) replaceChar);
			}
			lastpos = fromIndex + 3;
			fromIndex = sourceString.indexOf(separatorString,fromIndex + 3);
			if (fromIndex == -1) {
				sb.append(sourceString.substring(lastpos,sourceString.trim().length()));
			}
		}
	}

	return sb.toString();
}


/**
 * Insert the method's description here.
 * Creation date: (3/16/01 8:08:45 PM)
 * @return java.lang.String
 * @param numberOfSpaces int
 */
public static String replicateString(String string, int number) {
	String returnValue = "";
	if(number > 0){
		for (int i = 0; i < number; i++){
			returnValue += string;
		}
	}
	return returnValue;
}
/**
 * This method accepts date in any format and converts it in MM/DD/YYYY format
 * Creation date: Sep 07, 2004
 * @param date - java.sql.Date
 * @return String
 * @author karamat
 */

public static String changeFormate(java.sql.Date date)
{
	String  convertedDate = "";
    try{
    	if(date != null){
			DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss a");
			convertedDate = dateFormat.format(date);
    	}
	}
	catch (Exception e){
		e.printStackTrace();
	}
	return convertedDate;

}

/**
 * This method returns the date after after the days specified in parameter from
 * current date
 * Creation date: Sep 08, 2004
 * @param days - long
 * @return java.sql.Date
 * @author karamat
 */

public static java.sql.Date getDateAfter(int days)
{
	//String  convertedDate = "";
	Date utilDate = new Date();
	int year = 0;
	int month = 0;
	try
	{
		Calendar calendar = new GregorianCalendar();
		days = days + calendar.get(Calendar.DAY_OF_MONTH);
		month = calendar.get(Calendar.MONTH);
		year = calendar.get(Calendar.YEAR);
		if(days > getMaximumDaysInMonth(utilDate))
		 {
		 	month = month + 1;
		 	days = days - getMaximumDaysInMonth(utilDate);
		 }
		 if(month > 12)
		 {
		 	year = year + 1;
		 	month = 0; //in java.Calendar month index starts from 0
		 }
		calendar.set(year, month, days);
		utilDate = calendar.getTime();
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
	return new java.sql.Date(utilDate.getTime());
}


/**
 * This method returns the date after after the days specified in parameter from
 * current date
 * Creation date: Sep 08, 2004
 * @param days - long
 * @return java.sql.Date
 * @author karamat
 */

public static String getTimeStamp()
{
	//Current Time
	long currentTime = System.currentTimeMillis();
	
	//Current Time converted to Date Object
	Date current_date_time = new Date(currentTime);

	//Format the date to any pattern you want
	SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy_hh.mm.ss");
	String time = sdf.format(current_date_time);
		
	return time;
	
}


public static String getTimeDate()
{
	//Current Time
	long currentTime = System.currentTimeMillis();
	
	//Current Time converted to Date Object
	Date current_date_time = new Date(currentTime);

	//Format the date to any pattern you want
	SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss a");
	String time = sdf.format(current_date_time);
		
	return time;
	
}


public static String getSQLTimeDate()
{
	//Current Time
	long currentTime = System.currentTimeMillis();
	
	//Current Time converted to Date Object
	Date current_date_time = new Date(currentTime);

	//Format the date to any pattern you want
	SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss z");
	String time = sdf.format(current_date_time);
		
	return time;
	
}

/**
 * This method returns the maximum days of the month
 * Creation date: Sep 08, 2004
 * @param date - Date
 * @return int
 * @author karamat
 */

public static int getMaximumDaysInMonth(Date date)
{
		int maximumDays = 0;
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		int month = calendar.get(Calendar.MONTH) + 1; // because java.Calendar.MONTH start from 0 index and months from 1
		int year =  calendar.get(Calendar.YEAR);
		if((month == 1) || (month == 3) || (month == 5) || (month == 7) ||(month == 8) ||(month == 10) ||(month == 12))
		{
			maximumDays = 31;
		}
		if((month == 4) || (month == 6) || (month == 9) || (month == 11))
		{
			maximumDays = 30;
		}
		if(month == 2)
		{
			if(year % 4 == 0)
			 {
			 	maximumDays = 29;
			 }
			 else
			 {
			 	maximumDays = 28;
			 }
		}
		return maximumDays;
}



public static java.sql.Date addDaysToDate(Date date, int days)
{
      java.sql.Date futureDate = null;

      long lMilliSecondsInOneDay = 1000 * 60 * 60 * 24;

      long lMilliSecondsToAdd = days * lMilliSecondsInOneDay;

      futureDate = new java.sql.Date(date.getTime() + lMilliSecondsToAdd);

      return futureDate;
}
// return date less than number of days from current date
public static java.sql.Date subtractDaysToDate(int days)
{
      java.sql.Date pastDate = null;
	  java.sql.Date date = getCurrentSQLDate();
      long lMilliSecondsInOneDay = 1000 * 60 * 60 * 24;

      long lMilliSecondsToSubtract = days * lMilliSecondsInOneDay;

      pastDate = new java.sql.Date(date.getTime() - lMilliSecondsToSubtract);

      return pastDate;
}

public static java.sql.Date subtractDaysToDate(java.sql.Date date,int days)
{
      java.sql.Date pastDate = null;

      long lMilliSecondsInOneDay = 1000 * 60 * 60 * 24;

      long lMilliSecondsToSubtract = days * lMilliSecondsInOneDay;

      pastDate = new java.sql.Date(date.getTime() - lMilliSecondsToSubtract);

      return pastDate;
}

	/**
	 * This method splits the string on specified tokens and returns trimmed Strings as String[] 
	 * @param value
	 * @param token
	 * @return String[]
	 * @throws Exception
	 */
	public static String[] split(String value, String token) throws Exception{		
		String[] values = null ;
		ArrayList vals = new ArrayList();
		
		StringTokenizer st = new StringTokenizer(value, token);
			
		while (st.hasMoreTokens()) {	  				
			vals.add((st.nextToken()).trim())	;	  				
		} // end while
			
		values = new String[vals.size()] ;
		vals.toArray(values) ;
				
		return values ;
	} // end split()
	
	/**
	 * This method splits the string on specified tokens and returns trimmed Strings as Vector
	 * @param value
	 * @param token
	 * @return Vector
	 * @throws Exception
	 */
	public static Vector splitToVector(String value, String token) throws Exception{		
		Vector vals = new Vector();

		StringTokenizer st = new StringTokenizer(value, token);
		String element = "" ;
		while (st.hasMoreTokens()) {	 			
			element = getStringValue(st.nextToken(), "") ;
			vals.add(element)	;	  				
		} // end while			
				
		return vals ;

	} // end split()	
	

	  /**
	   * This method replaces the token in the specified string with replacement value
	   * @param strVal String
	   * @param token String
	   * @param replacement String
	   * @return String
	   */
	public static String replace(String strVal, String token, String replacement) {
	   StringBuffer buff = new StringBuffer("");
	   
	   int start = 0;
	    
	   int tokenLen = token.length();    
	   int lastFoundAt = strVal.indexOf(token);
	
	   while (lastFoundAt != -1) {
	     buff.append(strVal.substring(start, lastFoundAt));
      	 buff.append(replacement);
	
	     start = lastFoundAt + tokenLen;
	     lastFoundAt = strVal.indexOf(token, start);
	   } // end while
	   buff.append(strVal.substring(start));
	   return  buff.toString();
	} // end method replace()
	  	
	/**
	 * This methos return the string after converting the big decimal, if the value is
	 * null it returns the preferredValue value provided
	 * @param bigDecimal
	 * @param preferredValue
	 * @return
	 */
	public static String getStringValue(BigDecimal bigDecimal, String preferredValue){		
		return (bigDecimal == null ? preferredValue : bigDecimal.toString());
	}

	/**
	 * This method return the empty vector if the vector contains the null.
	 * @param vector - Vector
	 * @return Vector
	 */
	public static Vector ifNullVector(Vector vector){		
		return (vector == null ? new Vector() : vector);
	}

	/**
	 * This method compares available and assigned vector elements if one element exist in the 
	 * assigned then this function removes this element from the available vector.
	 * @param available - Vector, assigned - Vector
	 */
	public static void compareVectorElements(Vector available, Vector assigned)
	{		
		for(int i=0;i<assigned.size();i++)
		{					
			String assignedValue = (String)assigned.elementAt(i);
			for(int j=0;j<available.size();j++)
			{
				String availableValue = (String)available.elementAt(j);
				if(assignedValue.equalsIgnoreCase(availableValue))
				{
					// if assigned value exist in available remove it
					available.removeElementAt(j);
				}
			}
		}
	}


	/**
	 * This methos return the trimmed string, if the value is
	 * null it returns the preferredValue as provided
	 * @param value - Character
	 * @param preferredValue
	 * @return
	 */
	public static String getStringValue(Character value, String preferredValue){		
		return (value == null ? preferredValue : value.toString());
	}

	/**
	 * This methos return the trimmed string, if the value is
	 * null it returns the preferredValue as provided
	 * @param value - String
	 * @param preferredValue
	 * @return
	 */
	public static String getStringValue(String value, String preferredValue){		
		return (value == null ? preferredValue : value.trim());
	}

	/**
	 * This methos return the trimmed Object, if the value is
	 * null it returns the preferredValue as provided
	 * @param value - Object
	 * @param preferredValue
	 * @return
	 */
	
	public static String getStringValue(Object value, String preferredValue){		
		return (value == null ? preferredValue : value.toString() );
	}

	
	/**
	 * This method returns the trimmed string, if the value is
	 * null it returns the preferredValue as provided
	 * @param value - Date
	 * @param preferredValue
	 * @return
	 */
	public static String getStringValue(Date value, String preferredValue){		
		return (value == null ? preferredValue : value.toString());
	}
	
	/**
	 * This method is used to remove the spaces present in the string.
	 * @param value - String
	 * @return String
	 */
	
	public static String removeSpace(String objectName)
	{
	  objectName = getStringValue(objectName,"");
	  String convertedName = "";
	  String token = "";
	  StringTokenizer tokenizer = new StringTokenizer(objectName);
	  while(tokenizer.hasMoreTokens())
	   {
		  token = tokenizer.nextToken();
		  convertedName = convertedName + token;
	   }
	  return convertedName;
	}	
	
	/**
	 * This methos return the int after converting the big decimal, if the value is
	 * null it returns the preferredValue value provided
	 * @param bigDecimal
	 * @param preferredValue
	 * @return
	 */
	public static int getIntValue(BigDecimal bigDecimal, int preferredValue){		
		return (bigDecimal == null ? preferredValue : bigDecimal.intValue());
	}	
	

	/**
	 * This methos return the Date, if the value is
	 * null it returns the preferredValue value provided
	 * @param date
	 * @param preferredValue
	 * @return
	 */
	public static Date getDateValue(Date date, Date preferredValue){	
		return (date == null ? preferredValue : date);
	}
	

	/**
	 * This methos return the BigDecimal value, if the value is
	 * null, or some string which can not be a BigDecimal it returns the preferredValue as provided
	 * @param value - String
	 * @param preferredValue - long
	 * @return
	 */
	public static BigDecimal getBigDecimalValue(String value, long preferredValue){
		
		BigDecimal bigDecimal = null;
		
		try{
			bigDecimal = new BigDecimal(getStringValue(value, "")) ;
		}catch(Exception ex){
			bigDecimal = new BigDecimal(preferredValue) ;
		}
		
		return bigDecimal ;
	}
	
	/**
	 * This methos return the BigDecimal value, if the value is
	 * null it returns the preferredValue as provided
	 * @param value - BigDecimal
	 * @param preferredValue - long
	 * @return
	 */
	public static BigDecimal getBigDecimalValue(BigDecimal value, long preferredValue){		
		return (value == null ? new BigDecimal(preferredValue) : value);
	}
	

}
